package com.ysd.lis.service.self.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysd.common.Result;
import com.ysd.lis.entity.qc.QcInstrItemRule;
import com.ysd.lis.entity.slef.SelfFunction;
import com.ysd.lis.mapper.self.SelfFunctionMapper;
import com.ysd.lis.service.self.SelfFunctionService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wh
 * @since 2025-05-12
 */
@Service
public class SelfFunctionServiceImpl extends ServiceImpl<SelfFunctionMapper, SelfFunction> implements SelfFunctionService {

    @Override
    public Result findFunctionList(SelfFunction selfFunction) {
        LambdaQueryWrapper<SelfFunction> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SelfFunction::getDelFlag, 0);
        if (StringUtils.isNotBlank(selfFunction.getFuncName())) {
            queryWrapper.and(wrapper -> wrapper.like(SelfFunction::getFuncCode, selfFunction.getFuncName())
                    .or().like(SelfFunction::getFuncName, selfFunction.getFuncName()));
        }
        queryWrapper.orderByAsc(SelfFunction::getSeq);
        List<SelfFunction> databaseList = this.list(queryWrapper);

        return Result.succ(1, "查询成功", databaseList);
    }

    @Override
    public Result addFunction(SelfFunction selfFunction) {
        boolean save = this.save(selfFunction);
        if (save) {
            return Result.succ(1, "添加成功！", null);
        } else {
            return Result.fail("添加失败！");
        }
    }

    @Override
    public Result editFunction(SelfFunction selfFunction) {
        boolean b = this.updateById(selfFunction);
        if (b) {
            return Result.succ(1, "编辑成功！", selfFunction);
        } else {
            return Result.fail("编辑失败！");
        }
    }
}
